<?php

/*
 * To change this layout, choose Tools | Layouts
 * and open the layout in the editor.
 */

class Erra_System_FormRenderer_None extends Erra_System_FormRenderer {

    /**
     * Erra_System_FormRenderer::_editField() - Displays an Erra_Fields_Base_Object
     *
     * @param mixed $field
     * @param mixed $actionMethod
     * @return
     */
    public static function _editField($field, $actionMethod) {
        $res = '';
        $objectId = $field->getObjectId();
        $fieldDiv = 'FIELD_' . $field->getObjectId();
        $title = (!is_null($field->getDescription())) ? $field->getDescription() : $field->getObjectId();

        $res = '<div id="' . $fieldDiv . '"  ' . $field->getHtmlAttributes(array('class' => 'erra-field')) . ' role="dialog">';
        $res .= '<div class="erra-form-custom-dialog_header css3legacy">';
        $res .= '<span  id="">' . $title . '</span>';
        $res .= '<span class="pointer erra-form-common-close_button" role="button"><div class="erra-form-none-close_button">&nbsp;</div></span>';

        $res .= '</div>';
        $res .= '<div id="FIELD_' . $objectId . '_CONTENT" class="erra-form-custom-div_inside css3legacy">'; // main content
        $res .= self::startForm($field, $actionMethod, true);
        $res .= self::_editFieldRecursive($field, $actionMethod);

        $res .= '<div style="clear:both;"></div>';
        if ($field->getActionName() != null) {
            $res .= '<center><input class="erra-form-common-submit_button" name="' . $actionMethod . '" type="submit" value="' . $field->getActionName() . '"/></center>';
        }
        $res .= self::endForm($field);

        $res .= '</div>';
        $res .= '</div>';

        return $res;
    }

    /**
     * Erra_System_FormRenderer::_editFieldArray() - Displays an object array
     *
     * @param mixed $field
     * @param mixed $actionMethod
     * @return
     */
    public static function _editFieldArray($field, $actionMethod) {
        $res = '';
        $fieldName = $field->getObjectId();
        $fieldDesc = $field->getDescription();

        $array = $field->getObjectDataArray();
        $title = is_null($fieldDesc) ? $field->getObjectId() : $fieldDesc;
        $res .= '<div id="FIELD_LIST_' . $fieldName . '" data-object="'.$field->getTableName().'" ' . $field->getHtmlAttributes(array('class' => 'erra-field')) . '  role="dialog">';

        $res .= '<div class="erra-form-custom-dialog_header css3legacy">';
        $res .= '<span>' . $title . '</span>';
        $res .= '<span class="pointer erra-form-common-close_button" role="button"><div class="erra-form-none-close_button">&nbsp;</div></span>';

        $res .= '</div>';

        $res .= '<div id="divGridArray_' . $fieldName . '" class="erra-form-custom-div_inside css3legacy">';

        $res .= self::editRefreshHidden($field, $actionMethod);
        // add instance button, if exists
        if ($field->isCrud('C')) {
            $res .= self::editAddButton($field, $actionMethod, false);
        } else {
            $objectId = $field->getObjectId();
            $res .= '<div id = "FIELDADD_' . $objectId . '">';
            $res .= '</div>';
        }
        $res .= '<br/>';
        $res .= self::editSearchModule($field);

        $res .= (count($array) > 0) ? '<div id="divPaginatorElement_' . $fieldName . '"></div>' : '';

        if ((count($array) > 0)) {
            $aFieldPrototype = $array[0];
            $res .= self::_editTableHeader($field);
            $res .= '<tbody>';
            // Create a clone for all add/delete buttons
            $fieldClass = $field->getObjectClass();
            $aFieldClone = new $fieldClass('fieldClone');
            $aFieldClone->setRenderEngine($field->renderEngine);
            foreach ($array as $position => $aFieldData) {
                $res .= self::_editRow($aFieldClone, $aFieldData, $position, $actionMethod);
            }
            $res .= '</tbody>';
            $res .= self::_editTableClosure();
        }

        // Hidden form to refresh list
        $res .= self::startCallbackForm($field, 'AdminAction/refreshList');
        $res .= self::endForm($field);

        $res .= '</div>';
        $res .= '</div>';
        return $res;
    }

    /**
     * Erra_System_FormRenderer::displayMultiple() - Displays accordion field
     *
     * @param mixed $field
     * @param mixed $actionMethod
     * @return
     */
    public static function displayMultiple($field, $actionMethod) {
        $res = '';
        $instId = $field->isInstance() ? $field->getInstanceId() : '';
        $objectId = $field->getObjectId();
        $formId = 'refreshableRegion_' . $objectId;
        $res .= '<br/><div id="' . $formId . '"  >';
        $res .= '<div id="divMultiple_' . $field->getHtmlId() . '" class="erra-form-common-accordion_container">';


        foreach ($field->getAllInstances() as $anInstance) {
            $res .= '<div class="erra-form-custom-accordion_field_content css3legacy">';
            $res .= '<h3 class="erra-form-custom-accordion_h3">';
            $res .= $field->getDescription() . ' n°' . ($anInstance->getInstanceId() + 1);
            //$res .= '<span class="erra-form-common-delete_accordion_item"><a href="#" id="divMultipleDelete_' . $field->getHtmlId() . '"> X </a></span>';
            $res .= '</h3>';
            $res .= '<div id="divMultipleInstance_' . $anInstance->getHtmlId() . '" class="erra-form-custom-accordion_field_content">';
            $res .= self::_editFieldRecursive($anInstance, $actionMethod, $anInstance->getInstanceId());
            $res .= '<br/></div>';
            $res .= '</div>';
        }
        $res .= '</div>';
        $res .= '</div>';
        $res .= '<br/>';
        return $res;
    }

}

?>
